/*---------------------------------------------------------------------------
	ZaRan	-	A Totallly Automatic CFD Software
	Copyright (C) ,Since 2020
-------------------------------------------------------------------------------
License
	This file is part of ZaRan.

!	@file		gird.h
!	@brief	the purpose of this file.
!	@author	Chen Jie.
\*---------------------------------------------------------------------------*/
#include"Utility/include/LastSquare.h"
Eigen::VectorXd LastSquare::Solver()
{
  if (solver_type_ == 0)
    SolverNormalMatrix();
  else if (solver_type_ == 1)
    SolverSVD();
  else
    SolverColPivHouseholderQR();
  return x_;
}
void LastSquare::SolverSVD()
{
  x_ = A_.bdcSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(b_).transpose();
}

void LastSquare::SolverColPivHouseholderQR()
{
  x_ = A_.colPivHouseholderQr().solve(b_).transpose();
}

void LastSquare::SolverNormalMatrix()
{
  x_ = (A_.transpose() * A_).ldlt().solve(A_.transpose() * b_).transpose();
}
